package main

import (
	"github.com/kataras/iris"
	"global/structs"
	"time"
	"server/order/model"
	"github.com/ngaut/log"
)

// 基础信息
func onInfoRequest(ctx iris.Context) {
	c := bk.Configuration
	info := structs.ServBaseInfo{
		Name: 		c.App.Name,
		Ip: 		c.Http.Ip,
		Port: 		c.Http.Port,
		LogOn: 		c.Log.On,
		Duration: 	time.Since(bk.startTime).String(),
	}
	ApiSuccess(ctx, info)
}

// 添加交易对，上币逻辑
func onAddCoinPair(ctx iris.Context) {
	coinPair := ctx.URLParam("coin_pair")
	if coinPair == "" {
		ApiError(ctx, ERR_PARAMETER)
		return
	}

	if bk.Data.CheckCoinPairExists(coinPair) {
		ApiSuccess(ctx, "success")
		return
	}

	item, err := model.CoinPairModel.GetFirst(coinPair)
	if err != nil {
		log.Errorf("get coin pair from db failed, msg: %s", err.Error())
		ApiError(ctx, ERR_COINPAIR_NOT_EXISTS)
		return
	}

	if item.Enabled != model.COIN_PAIR_ENABLED {
		log.Errorf("coin pair status not right, item: %v", item)
		ApiError(ctx, ERR_COINPAIR_NOT_ENABLE)
		return
	}

	bk.Data.AddCoinPair(*item)

	ApiSuccess(ctx, "success")
}
